               * * * Strings Now Handled, the SNH Interpreter (tiny) * * *

A 180 line Novelty Interpreter the source still with comments, blank lines 
and debug code remaining but commented out, 
written in SmallBASIC 0.12.9 bas code.


                                            * * * History * * *
This is a sort of evolving process starting from the BrainF*** Interpreter >
Be Quicker, BQ Interpreter, less tedious but still "impossible" to code 
(and enjoy doing so).

With Everything Is Number, EIN version, coding became possible because
the problem of how to do IF ELSE END IF stuff was solved. Then onto
Is Everything Number?, IEN Interpreter, which adds unary functions to the mix. 
(Just a couple to show how it's done, INT, RND, NOT (which was never tested).

In IEN (Is Everything Numbered) Interpreter the memory() array was numeric.
Now for SNH, we switch the memory array to string and use VAL to convert
some of the strings to numeric values.

			
                                          * * * Description * * *
The program written in a text Editor like Notepad, is divided  into 3 parts.
1. The comment section is first before any {###} commands for string storage.
    You can fit a book into this section, just don't use and {} symbols in your
    literary artwork.

2. String/data storage section, list numbers, strings and functions you will
    need for the program. Current functions are NOT, RND, INT for Numbers.
    CTR, CLS, COLOR, LOCATE for Screen Control and LEN, MID1, MID2, INSTR1
    and INST2.
     
    A memory data line looks like this:
    {n}  My string with leading and ending spaces   that ends here > ;

    The curly brackets signal a data item, n the place in the memory array to 
    store it. Immediately following the } is the start of the string to store. If
    you want leading spaces put them in, if storing numeric data item then 
    leading spaces not advised. The end of the string is signaled by a ; 
    semi-colon.

    The end of this section is signalled by {0} or anything like{end} that VAL will
    return as 0, negative numbers also would work eg(-1)  
 
3. The actual program commands that manipulate the data from section 2.
    All commands are a single command letter/symbol, some are followed by
    numbers some are not. All spaces, CR, LF, Tabs... are stripped before the
    Interpreter goes to work executing commands, so white space the commands
    anyway you like to keep it as readable as possible for yourself (no comments
    should go in this section).
  

                            * * * Coding *SNH.txt programs (part 3) * * *
Number digits/symbols:
-.1234567890 are reserved for number values.
Note: - sign is just used for making a number value negative; 
the ~ sign is actually used for the binary operation of subtraction.

Command Characters: ?ABCDFMIENP[X]%^/*~+=<>()!&|

                ?ABCDFMW are followed by a number, say n.

                IEN are for IF... THEN... ELSE... END IF blocks.

                                   [X] are for loops. 

          %^/*~+=<>()!&| are the 14 Binary Operator Symbols.

These commands are followed by a number (n): ?ABCDFMW

I/O
Wn - Writes a number from memory$(n), the cursor stays where it is.
?n - Gets Input and stores it into memory(n).

Memory storing
An - stores memory(n) into memory(1)
Bn - stores memory(n) into memory(2)
Cn - stores memory(n) into memory(3)
Dn - stores memory(n) into memory(4)
Fn - stores the result of a F for Function (if any) at memory(0) to memory(n)
       more about this below
Mn - like F takes whatever is in Memory(0) and stores to memory(n)

All the Binary Operators %^/*~+=<>()!&| perform their assigned task with
operands in memory(1) and memory(2) and store the results in memory(0). 
Described in more detail below.


So as you can see Memory(0-4) are specially reserved sections of the memory
array.

These commands are NOT followed by numbers: IENP[X] and all the operators.

IEN commands for IF... THEN... ELSE... END IF blocks, THEN is not used and 
ELSE is optional:
I is for IF
E is for ELSE
N is for END IF 

I checks memory(0) to see if it should seek E|N when memory(0) = 0 or do
the next code section when memory(0) <> 0. 
When E is hit from I block we look for N on same level as it. (OK to nest.)
N is just there as an end of block marker.

P just starts next printing on next line.

[X] are the 3 command letters for loop structure:
[ is for DO 
] is for LOOP
X is for eXit, your only way out of the loop, typically after an If decision
which comes after a Boolean Binary Operation.

%^/*~+=<>()!&|  Operators: 
An Bn load memory(1) and memory(2) then an operator evaluates the
relation and stores the value in memory(0). 
The Wn, I, Mn, Fn all read memory(0) and do their thing with it.

14 Binary Operator Symbols:

6 Numeric Return Operators:
% is MOD or Modulus, 10 % 3 = 1 
^ is power,  10 ^ 3 = 1000
/ is divide 10 / 3 = 1.3333...
* is multiply 10 * 3 = 30
~ is subtraction NOT - (used to make a number negative),  10 ~ 3 = 7
+ is addition 10 + 3 = 13

          ***    Repeat: use ~ for Subtraction NOT - sign. ***

8 Boolean's return operators false = 0 ,  -1 is set for when <> 0
= is Equal test returns -1 in memory(0) if true else 0
< is Less Than test,  10 < 3 returns 0 in memory(0)
> is Greater Than test, 10 > 3 returns -1 in memory(0)
( is <=  Less Than or Equal test,  10 ( 3 returns 0 in memory(0)
) is >= Greater Than or Equal test, 10 ) 3 returns -1 in memory(0)
! is for not, here it means <> or != NOT Equal, 3 ! 10 returns -1 in memory(0)
& is for AND if memory(1) <> 0 AND memory(2) <> 0, then -1 in memory(0)
| is used for OR so if either memory(1) <>0 OR memory(2) <> 0, 
    then memory(0) = (set to) -1 else memory(0) = (set to) 0

*** Notice curves of:  < (   and  > )  best one symbol to replace two? ***


More About Functions:

Function setup and execution Steps:
1. Store the function name in a memory location, {n}COLOR;
    Store any parameters it might need also in this section eg:
    {101}7;
    {102}1;
2. An puts this name into memory(1) eg:
    A100
3. Bn set the memory location for parameter value the function is to use.
    B101
4. Cn, ditto #3 if two parameters
    C103
5. Dn, ditto #4 if 3 parameters
6. Fn calls the function execution and stores the result (if any) to memory(n).
    F9
    I use 9 as a "dummy" location, COLOR 7, 1 does not return a value

Functions currently available in this SNH Interpreter version:

                                       * * * Number * * *
NOT - (never been tested) compares memory(2), setup with Bn command,
           to 0. If memory(2) = 0 then returns -1 else returns 0 in memory(0)
           which the Fn execution reads and loads memory(n) with result.

RND - does not need any parameters, just An and Fn.

INT - converts memory(2) to Integer and store at memory(n) of Fn.

                                        * * * Screen * * *
CTR - prints memory(2) on screen centered in current row.

CLS - clears screen, not parameters need be set, just An Fn

COLOR - discussed in Function setup and execution steps.

LOCATE - row, column of character cell are Bn Cn parameters.


                                        * * * String * * *
LEN - Bn's length in characters

MID1 - two parameter MID$ function, the end section of Bn starting at Cn

MID2 - 3 parameters MID$ function, the section of Bn start at Cn for length Dn.

INSTR1 - (not tested) first string location of Cn found in Bn.

INSTR2 - (not tested) string location of Dn found in Cn starting at Bn.



If you read through all this, you are probably more a reader than I.

Thanks, I hope it is at least a little fun to play with, 

B+                     2017-08-02 edit